<?php
class Bobot_model extends Model{
	
	function bobot_model(){
		parent::Model();
	}
	
	var $table = 'bobot'; //inisiasi nama tabel
	
	function simpan($data){
		$this->db->insert($this->table,$data);
	}
	
	function del($id){
		$this->db->delete($this->table,array('id_bobot' => $id));
	}
	
	function upd($id,$data){
		$this->db->where('id_bobot',$id);
		$this->db->update($this->table,$data);
	}
	
	function get(){
		return $this->db->get($this->table)->result();
	}
	
	function get_byid($id){
		//$this->db->where('id_bobot',$id);
		//return $this->db->get($this->table)->row();
		return $this->db->get_where($this->table, array('id_bobot' => $id))->row();
	}
	
	function get_max_id(){
		$id_la = 0;
		$this->db->select_max('id_bobot','max_id');
		$has = $this->db->get($this->table);
		foreach($has->result() as $ha){
			$id_la = $ha->max_id;
		}
		if ($id_la == 0){
			$id_ba = 1;
		}
		else {
			$id_ba = $id_la+1;
		}
		return $id_ba;
	}
	
	function get_bobot_by_id($id)
	{
		return $this->db->get_where($this->table, array('id_bobot' => $id))->row();
	}
	
	function count_table(){
		return $this->db->count_all($this->table);
	}
}
?>